package com.mr_ladeng.listview;

import java.util.ArrayList;
import java.util.HashMap;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.mr_ladeng.listviewnest.R;

/**
 * 
 * @项目名称：	Mr_ladeng_wish
 * @类名称： 	ChildAdapter.java
 * @创建人：	Mr.ladeng (zbl704@yeah.net)
 * @创建时间： 2015-4-22上午11:55:10
 * @修改备注：    
 * @version 1.0   
 * @类描述：	还愿之旅 	评论列表适配器	adapter
 */
public class ChildAdapter extends BaseAdapter {
	private Context context;
	private LayoutInflater inflater;
//	List<PullBeanRedeemChild> pullBeanRedeemChild2 ;
	

	private ArrayList<HashMap<String, Object>> pullBeanRedeemChild ;

	public ChildAdapter(Context context) {
		super();
		this.inflater = LayoutInflater.from(context);
		this.context = context;
	}
	
//	public void addAll(List<PullBeanRedeemChild> pullBeanRedeemChild2) {
//		this.pullBeanRedeemChild2 = pullBeanRedeemChild2;
//			notifyDataSetChanged();
//	}
	
	public void addAll(ArrayList<HashMap<String, Object>> pullBeanRedeemChild) {
		this.pullBeanRedeemChild = pullBeanRedeemChild ;
		notifyDataSetChanged();
	}

	public void clearAll() {
		this.pullBeanRedeemChild.clear();
		notifyDataSetChanged();
	}
	@Override
	public int getCount() {
		
		if (pullBeanRedeemChild == null) {
			return 0;
		}
		return pullBeanRedeemChild.size();
		
	}

	@Override
	public Object getItem(int position) {
		return pullBeanRedeemChild.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		ViewHoder viewHoder = null;
		if (convertView == null) {
			
			viewHoder = new ViewHoder();
		    inflater = LayoutInflater.from(context);
		    
			convertView = inflater.inflate(R.layout.childitem, null, false);
			
//			viewHoder.child_reply_tv = (TextView) convertView
//					.findViewById(R.id.child_reply_tv);
			
//			viewHoder.childThisName = (TextView) convertView
//					.findViewById(R.id.child_this_name);//评论人A
			
//			viewHoder.childToName = (TextView) convertView
//					.findViewById(R.id.child_to_name);//评论人B
//			viewHoder.childToContent = (TextView) convertView
//					.findViewById(R.id.child_to_content);//评论内容
			
			viewHoder.childThisName = (TextView) convertView.findViewById(R.id.child_this_name);
		        String ttt = "嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻嘻";
		        String sss = "哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈";
		        SpannableString spanttt = new SpannableString(ttt);
		        SpannableString spansss = new SpannableString(sss);
		        ClickableSpan clickttt = new ShuoMClickableSpan(ttt, context);
//		        ClickableSpan clicksss = new CopyOfShuoMClickableSpan(ttt, context);
		        spanttt.setSpan(clickttt, 0, ttt.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
//		        spansss.setSpan(clicksss, 0, sss.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
		        viewHoder.childThisName.setText("哈哈");
		        viewHoder.childThisName.append(spanttt);
		        viewHoder.childThisName.append("你是谁你谁你是谁你谁你是谁你谁");
		        viewHoder.childThisName.append(spansss);
		        viewHoder.childThisName.append("你是谁你谁你是谁你谁你是谁你谁你是谁你谁你是谁你谁");
		        viewHoder.childThisName.setMovementMethod(LinkMovementMethod.getInstance());
			
			
			
			
			convertView.setTag(viewHoder);
			
		} else {
			
			viewHoder = (ViewHoder) convertView.getTag();
		}
		
		
//		PullBeanRedeemChild redeemChild = pullBeanRedeemChild2.get(position);
	
//			viewHoder.childThisName.setText("咳嗽");
//			viewHoder.childToName.setText("计算机");
//			viewHoder.childToContent.setText("计算机的今生今世");
		
		
//		viewHoder.childThisName.setText((CharSequence) pullBeanRedeemChild.get(position).get("nickname_1"));
//		viewHoder.childToName.setText((CharSequence) pullBeanRedeemChild.get(position).get("nickname_2"));
//		viewHoder.childToContent.setText((CharSequence) pullBeanRedeemChild.get(position).get("rea_message_content"));
		
		
		return convertView;
	}
	
		public class ViewHoder {
			
		TextView child_reply_tv ;
		TextView childThisName , childToName , childToContent ;
		
	}
		
		public class ShuoMClickableSpan extends ClickableSpan {
		     
			    String string;
			    Context context;
			    public ShuoMClickableSpan(String str,Context context){
			        super();
			        this.string = str;
			        this.context = context;
			    }
			     
			     
			    @Override
			    public void updateDrawState(TextPaint ds) {
			        ds.setColor(Color.BLUE);
			    }
			 
			 
			    @Override
			    public void onClick(View widget) {
			        Intent intent = new Intent();
			        intent.setClass(context, Activity_2.class);
			        context.startActivity(intent);
			 
			    }
			 
			}


}
